<div style="padding: 15px;" class="layui-form">
 <div class="layui-form-item">
  <input type="hidden" value={$role.id} id="role_id"/>
    <label class="layui-form-label">名称:</label>
    <div class="layui-inline" style="width:150px;">
     <input type="text" class="layui-input" value={$role.role_name} name="role_name" placeholder="角色名称" /> 
    
    </div>
     <div class="layui-inline" style="color:red;"><label  id="error_info" hidden></label></div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label" >权限:</label>
    <?php $all_role = explode(',',$role['role']);?>

  <div class="layui-input-block" >

      {foreach :config('role.role_id') as $k=>$v}
 <div class="layui-inline" >
     
      <label class="layui-form-label" style="padding-left: 0px;text-align: left;">{$k}:</label>

      {foreach $v as $kk=>$vv}
      <input type="checkbox" title="{$kk}" value={$vv} lay-skin="primary" {if in_array($vv,$all_role)}checked{/if}>
      {/foreach}

      </div>
<hr class="layui-bg-red">
  {/foreach}
 </div>
 	

  </div>

<div class="layui-form-item">

 <button class="layui-btn layui-btn-sm layui-input-block" id="sub">提交</button>
</div>
</div>

<script>
layui.use('form', function(){
  var form = layui.form;

});
$('input[name="role_name"]').focus(function(){
  $('#error_info').css('display','none');
})

$('#sub').click(function(){
  var role_name = $('input[name="role_name"]').val();
  if( role_name==''){
    $('#error_info').text('角色名称不能为空').css('display','block');
    return;
  }
  var role = '';
  $('input:checkbox:checked').each(function(){
     role+= $(this).val()+',';
  })
  if(role != '')
    role = role.substr(0,role.length-1);

  var role_id = $('#role_id').val();
  var info = {'id':role_id,'role_name':role_name,'role':role}
 
  $.post('/admin/role/edit/'+role_id,info,function(res){
    console.log(res);
    if(res)
       window.location.href = '/admin/role';
  })
})
</script>